/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package scubalogbook.data.imports.jdivelog;

import java.io.File;
import scubalogbook.data.imports.jdivelog.model.JDive;
import scubalogbook.data.imports.jdivelog.model.JDiveLog;
import scubalogbook.data.imports.jdivelog.util.UnitConverter;
import scubalogbook.data.model.Dive;

/**
 *
 * @author vkorecky
 */
public class JDiveLogImport {
    
    public void ConvertJDiveLogIntoScubaLogbook(File file) throws Exception {                
        JDiveLogLoad jDiveLogImporter = new JDiveLogLoad(file);
        JDiveLog jDiveLog = jDiveLogImporter.execute();                                
        
        if ((jDiveLog != null) && (scubalogbook.ScubaLogbookView.sqlite != null))
        {
            for(JDive jdive : jDiveLog.getDives())
            {
                ImportDive(jdive);
            }
        }
    }
    
    private void ImportDive(JDive jdive) {                                                
        if (jdive != null)
        {   
            // Create new dive
            Dive newDive = new Dive();
            
            UnitConverter unitConverter = new UnitConverter(UnitConverter.SYSTEM_SI, UnitConverter.getSystem(jdive.getUnits()));
            
            if (jdive.getAMV() != null) {                
                jdive.setAMV(unitConverter.convertAMV(jdive.getAMV()));
            }
            
            if (jdive.getAMV() != null) {                                
                jdive.setAMV(unitConverter.convertAMV(jdive.getAMV()));
            }            
        }
        
        
    }
}
